package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonFillBlankBean;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;

import java.util.List;

/**
 * Created by hyy on 2018/4/21.
 */

public class FillBlanAdapter extends TagAdapter<CartoonFillBlankBean> {
    Context mContext;

    public FillBlanAdapter(Context mContext, List<CartoonFillBlankBean> datas) {
        super(datas);
        this.mContext = mContext;
    }

    @Override
    public View getView(FlowLayout parent, int position, CartoonFillBlankBean cartoonFillBlankBean) {
        LinearLayout view = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.sentence_question_name_layout, parent, false);
        final TextView question = (TextView) view.findViewById(R.id.question_letter);


        if ("##".equals(cartoonFillBlankBean.getValue())) {

            switch (cartoonFillBlankBean.getStatus()) {
                case STATUS_DEFAULT:

                    /**---将隐藏的选项显示出来------**/
//                    for (int i = 0; i < optionsTextList.size(); i++) {
//                        if (String.valueOf(optionsTextList.get(i).getId()).equals(cartoonFillBlankBean.getId())) {
//                            optionsTextList.get(i).setHidden(0);
//                            optionsTextList.get(i).setStatus(null);
//                            cartoonFillBlankBean.setOptionValue("");
//                            cartoonFillBlankBean.setId("");
//
//                        }
//                    }

                    question.setText("");
                    question.setBackgroundResource(R.mipmap.cartoon_sentence_transparent_doted);
                    break;
                case STATUS_CHOOSE:
                    question.setText("");
                    question.setBackgroundResource(R.mipmap.cartoon_sentence_white_dotted);
                    break;
                case STATUS_WORD:
                    if (!TextUtils.isEmpty(cartoonFillBlankBean.getOptionValue())) {
                        question.setText(cartoonFillBlankBean.getOptionValue());
                    }
//                    /**---隐藏选项------**/
//                    for (int i = 0; i < optionsTextList.size(); i++) {
//                        if (String.valueOf(optionsTextList.get(i).getId()).equals(cartoonFillBlankBean.getId())) {
//                            optionsTextList.get(i).setHidden(1);
////                                optionsTextList.get(i).setValue("");
//                        }
//                    }
//
//                    if (adapter != null) {
//                        isShowCommit();
//                        adapter.notifyDataSetChanged();
//                    }

                    question.setBackgroundResource(R.mipmap.cartoon_sentence_white_dotted);
                    break;

                case STATUS_WRONG:
                    if (!TextUtils.isEmpty(cartoonFillBlankBean.getOptionValue())) {
                        question.setText(cartoonFillBlankBean.getOptionValue());
                        question.setBackgroundResource(R.mipmap.cartoon_word_long_wrong);
                    }
                    break;

                case STATUS_RIGHT:
                    if (!TextUtils.isEmpty(cartoonFillBlankBean.getOptionValue())) {
                        question.setText(cartoonFillBlankBean.getOptionValue());
                        question.setBackgroundResource(R.mipmap.cartoon_word_long_right);
                    }
                    break;
            }

        } else {
            question.setText(cartoonFillBlankBean.getValue());
            question.setBackground(null);
        }


        return view;
    }
}
